/*
 * @lc app=leetcode.cn id=2844 lang=golang
 *
 * [2844] 生成特殊数字的最少操作
 */
package Solutions

// @lc code=start
func minimumOperations__(num string) int {
	ans := 0
outer:
	for i := len(num) - 1; i >= 0; i-- {
		if num[i] != '0' {
			ans++
			continue
		}
		for i--; i >= 0; i-- {
			if num[i] == '0' || num[i] == '5' {
				break outer
			}
			ans++
		}
		// if i == -1 {
		// 	ans = len(num) - 1
		// }
	}
	ans1 := 0
outer1:
	for i := len(num) - 1; i >= 0; i-- {
		if num[i] != '5' {
			ans1++
			continue
		}
		for i--; i >= 0; i-- {
			if num[i] == '2' || num[i] == '7' {
				break outer1
			}
			ans1++
		}
		if i == -1 {
			ans1 = len(num)
			break
		}
	}
	if ans < ans1 {
		return ans
	}
	return ans1

}

// @lc code=end
